Public Class frmAddPlayer
    Inherits System.Windows.Forms.Form

    Private ptrNewPlayer As cmplib01.Player
    Friend WithEvents chkNoPlay As System.Windows.Forms.CheckBox
    Friend WithEvents lblNoplay As System.Windows.Forms.Label

    Private m_ActionCancelled As Boolean

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtPassword As System.Windows.Forms.TextBox
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents pnlTopBorder As System.Windows.Forms.Panel
    Friend WithEvents picCampaignerIcon As System.Windows.Forms.PictureBox
    Friend WithEvents txtTitleBox As System.Windows.Forms.TextBox
    Friend WithEvents lstFactions As System.Windows.Forms.ListBox
    Friend WithEvents lblFaction As System.Windows.Forms.Label
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents txtPlayerName As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmAddPlayer))
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.lblFaction = New System.Windows.Forms.Label
        Me.lstFactions = New System.Windows.Forms.ListBox
        Me.txtPlayerName = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.txtPassword = New System.Windows.Forms.TextBox
        Me.btnCancel = New System.Windows.Forms.Button
        Me.btnOK = New System.Windows.Forms.Button
        Me.pnlTopBorder = New System.Windows.Forms.Panel
        Me.picCampaignerIcon = New System.Windows.Forms.PictureBox
        Me.txtTitleBox = New System.Windows.Forms.TextBox
        Me.lblNoplay = New System.Windows.Forms.Label
        Me.chkNoPlay = New System.Windows.Forms.CheckBox
        Me.Panel1.SuspendLayout()
        Me.pnlTopBorder.SuspendLayout()
        CType(Me.picCampaignerIcon, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Panel1
        '
        Me.Panel1.BackColor = System.Drawing.Color.LightSkyBlue
        Me.Panel1.Controls.Add(Me.chkNoPlay)
        Me.Panel1.Controls.Add(Me.lblNoplay)
        Me.Panel1.Controls.Add(Me.lblFaction)
        Me.Panel1.Controls.Add(Me.lstFactions)
        Me.Panel1.Controls.Add(Me.txtPlayerName)
        Me.Panel1.Controls.Add(Me.Label2)
        Me.Panel1.Controls.Add(Me.Label1)
        Me.Panel1.Controls.Add(Me.txtPassword)
        Me.Panel1.Location = New System.Drawing.Point(6, 48)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(402, 214)
        Me.Panel1.TabIndex = 16
        '
        'lblFaction
        '
        Me.lblFaction.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblFaction.ForeColor = System.Drawing.Color.Black
        Me.lblFaction.Location = New System.Drawing.Point(15, 50)
        Me.lblFaction.Name = "lblFaction"
        Me.lblFaction.Size = New System.Drawing.Size(224, 16)
        Me.lblFaction.TabIndex = 6
        Me.lblFaction.Text = "Faction"
        '
        'lstFactions
        '
        Me.lstFactions.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lstFactions.Location = New System.Drawing.Point(8, 66)
        Me.lstFactions.Name = "lstFactions"
        Me.lstFactions.Size = New System.Drawing.Size(384, 54)
        Me.lstFactions.TabIndex = 5
        '
        'txtPlayerName
        '
        Me.txtPlayerName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtPlayerName.Location = New System.Drawing.Point(8, 24)
        Me.txtPlayerName.Name = "txtPlayerName"
        Me.txtPlayerName.Size = New System.Drawing.Size(384, 20)
        Me.txtPlayerName.TabIndex = 4
        Me.txtPlayerName.Text = "New Player"
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.ForeColor = System.Drawing.Color.Black
        Me.Label2.Location = New System.Drawing.Point(16, 128)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(224, 16)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "Enter Password"
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.Color.Black
        Me.Label1.Location = New System.Drawing.Point(16, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(224, 16)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "Player Name"
        '
        'txtPassword
        '
        Me.txtPassword.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtPassword.Location = New System.Drawing.Point(8, 144)
        Me.txtPassword.Name = "txtPassword"
        Me.txtPassword.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
        Me.txtPassword.Size = New System.Drawing.Size(384, 20)
        Me.txtPassword.TabIndex = 1
        '
        'btnCancel
        '
        Me.btnCancel.BackColor = System.Drawing.Color.LightSkyBlue
        Me.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnCancel.ForeColor = System.Drawing.Color.Black
        Me.btnCancel.Location = New System.Drawing.Point(332, 268)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(75, 23)
        Me.btnCancel.TabIndex = 15
        Me.btnCancel.Text = "Cancel"
        Me.btnCancel.UseVisualStyleBackColor = False
        '
        'btnOK
        '
        Me.btnOK.BackColor = System.Drawing.Color.LightSkyBlue
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.ForeColor = System.Drawing.Color.Black
        Me.btnOK.Location = New System.Drawing.Point(252, 268)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(75, 23)
        Me.btnOK.TabIndex = 14
        Me.btnOK.Text = "OK"
        Me.btnOK.UseVisualStyleBackColor = False
        '
        'pnlTopBorder
        '
        Me.pnlTopBorder.BackColor = System.Drawing.Color.SteelBlue
        Me.pnlTopBorder.Controls.Add(Me.picCampaignerIcon)
        Me.pnlTopBorder.Controls.Add(Me.txtTitleBox)
        Me.pnlTopBorder.Location = New System.Drawing.Point(0, 0)
        Me.pnlTopBorder.Name = "pnlTopBorder"
        Me.pnlTopBorder.Size = New System.Drawing.Size(418, 40)
        Me.pnlTopBorder.TabIndex = 13
        '
        'picCampaignerIcon
        '
        Me.picCampaignerIcon.Image = CType(resources.GetObject("picCampaignerIcon.Image"), System.Drawing.Image)
        Me.picCampaignerIcon.Location = New System.Drawing.Point(9, 11)
        Me.picCampaignerIcon.Name = "picCampaignerIcon"
        Me.picCampaignerIcon.Size = New System.Drawing.Size(16, 16)
        Me.picCampaignerIcon.TabIndex = 9
        Me.picCampaignerIcon.TabStop = False
        '
        'txtTitleBox
        '
        Me.txtTitleBox.BackColor = System.Drawing.Color.SteelBlue
        Me.txtTitleBox.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.txtTitleBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTitleBox.ForeColor = System.Drawing.Color.WhiteSmoke
        Me.txtTitleBox.Location = New System.Drawing.Point(32, 8)
        Me.txtTitleBox.Multiline = True
        Me.txtTitleBox.Name = "txtTitleBox"
        Me.txtTitleBox.ReadOnly = True
        Me.txtTitleBox.Size = New System.Drawing.Size(312, 26)
        Me.txtTitleBox.TabIndex = 8
        Me.txtTitleBox.Text = "Campaigner [Add Player]"
        '
        'lblNoplay
        '
        Me.lblNoplay.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblNoplay.ForeColor = System.Drawing.Color.Black
        Me.lblNoplay.Location = New System.Drawing.Point(16, 167)
        Me.lblNoplay.Name = "lblNoplay"
        Me.lblNoplay.Size = New System.Drawing.Size(224, 18)
        Me.lblNoplay.TabIndex = 7
        Me.lblNoplay.Text = """No Play"" Flag Option"
        '
        'chkNoPlay
        '
        Me.chkNoPlay.AutoSize = True
        Me.chkNoPlay.Location = New System.Drawing.Point(8, 187)
        Me.chkNoPlay.Name = "chkNoPlay"
        Me.chkNoPlay.Size = New System.Drawing.Size(63, 17)
        Me.chkNoPlay.TabIndex = 8
        Me.chkNoPlay.Text = "No Play"
        Me.chkNoPlay.UseVisualStyleBackColor = True
        '
        'frmAddPlayer
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.Black
        Me.ClientSize = New System.Drawing.Size(413, 303)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.pnlTopBorder)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Name = "frmAddPlayer"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Panel1.ResumeLayout(False)
        Me.Panel1.PerformLayout()
        Me.pnlTopBorder.ResumeLayout(False)
        Me.pnlTopBorder.PerformLayout()
        CType(Me.picCampaignerIcon, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub New(ByRef Play As cmplib01.Player, ByRef facts As cmplib01.Factions)
        Me.New()

        ptrNewPlayer = Play

        Dim key As String
        Dim fac As cmplib01.Faction

        For Each key In facts.HT.Keys
            fac = facts.Item(key)
            lstFactions.Items.Add(fac)
        Next

    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If UpdateProperties() = True Then
            Me.Hide()
        Else
            If lstFactions.SelectedItem Is Nothing Then
                MessageBox.Show("You must select a faction for this player.", "Select Faction", MessageBoxButtons.OK)
            End If

        End If
    End Sub

    Private Function UpdateProperties() As Boolean
        If lstFactions.SelectedItem Is Nothing Then
            Return False
        End If

        ptrNewPlayer.PlayerName = txtPlayerName.Text
        ptrNewPlayer.Password = txtPassword.Text

        If chkNoPlay.Checked Then ptrNewPlayer.NoPlay = True

        Dim fac As cmplib01.Faction = lstFactions.SelectedItem
        ptrNewPlayer.FactionKey = fac.Key
        Return True

    End Function

    Public ReadOnly Property ActionCancelled() As Boolean
        Get
            Return m_ActionCancelled
        End Get
    End Property


    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        m_ActionCancelled = True
        Me.Hide()
    End Sub
End Class
